import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    acc: window.localStorage.getItem('acc' || '[]') == null ? '' : JSON.parse(window.localStorage.getItem('acc' || '[]')).acc,
    step1: window.localStorage.getItem('step1' || '[]') == null ? '' : JSON.parse(window.localStorage.getItem('step1' || '[]')).step1,
    step2: window.localStorage.getItem('step2' || '[]') == null ? '' : JSON.parse(window.localStorage.getItem('step2' || '[]')).step2,
    step3: window.localStorage.getItem('step3' || '[]') == null ? '' : JSON.parse(window.localStorage.getItem('step3' || '[]')).step3,
    adminMenus: []
  },
  mutations: {
    initAdminMenu (state, menus) {
      state.adminMenus = menus
    },
    setStep1State (state, step1) {
      state.step1 = step1
    },
    setStep2State (state, step2) {
      state.step1 = step2
    },
    setStep3State (state, step3) {
      state.step1 = step3
    },
    login (state, acc) {
      state.acc = acc
      window.localStorage.setItem('acc', JSON.stringify(acc))
    },
    logout (state) {
      // 注意不能用 null 清除，否则将无法判断 acc 里具体的内容
      state.acc = ''
      window.localStorage.removeItem('acc')
      state.adminMenus = []
    }
  },
  actions: {}
})
